<template>
  <div id="app">
    <ul>
      <li v-for="(i, k) in arr" :key="(k = i.id)">
        <span>{{ i.id }}</span>
        <button @click="remove(i.id)">删除</button>
      </li>
    </ul>
    <button @click="add">生成</button>
  </div>
</template>

<script>
export default {
  // name: "",
  components: {},
  props: {},
  data() {
    return {
      arr: [{ id: Math.floor(Math.random() * 100) + 1 }],
    };
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    add() {
      const id = Math.floor(Math.random() * 100) + 1;
      const obj = {
        id,
      };
      this.arr.push(obj);
    },
    remove(id) {
      this.arr.splice(
        this.arr.findIndex((item) => item.id == id),
        1
      );
    },
  },
};
</script>

<style scoped></style>
